<script>
	import {
		request
	} from './utils/request.js'
	export default {
		onLaunch: function(options) {
			
			var launchOptions = wx.getLaunchOptionsSync();
			console.log('进来了', launchOptions)
			let businessId = ''
			if (launchOptions.scene === 1011 || launchOptions.scene === 1012) {
			  // 如果是从扫描二维码进入小程序的场景（1011和1012），则可以获取到扫描时传递的参数
			  var query = launchOptions.query;
			  businessId = query.businessId || ''
			  // 在这里处理获取到的参数，可以根据需要进行进一步操作
			  }
			this.login(businessId)
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		globalData: {
			token: ''
		},
		methods: {
			login(businessId) {
				return new Promise((resolve) => {
					wx.login({
						success: async (e) => {
							const res = await request(
								`/api/login?code=${e.code}&appids=wxce9af358240d359c&secret=7bb54ee600e9261fabfb02a2a8d46d0e`, {
									code: e.code,
									appids: 'wxce9af358240d359c',
									secret: '7bb54ee600e9261fabfb02a2a8d46d0e',
									businessId: businessId,
								})
							uni.setStorageSync('token', res.data.token)
							const res2 = await request('/api/userInfo', {}, 'get')
							uni.setStorageSync('userId', res2.data.data.id)
							uni.setStorageSync('userInfo', JSON.stringify(res2.data.data))
							resolve()
						}
					})
				})
			}
		}
	}
</script>

<style>
	*,
	view {
		box-sizing: border-box;
	}

	/*每个页面公共css */
	.flex {
		display: flex;
	}

	.items-center {
		align-items: center;
		justify-content: ;
	}

	.justify-center {
		justify-content: center;
	}

	.flex-col {
		flex-direction: column;
	}

	.justify-around {
		justify-content: space-around;
	}

	.justify-between {
		justify-content: space-between;
	}

	.flex-1 {
		flex: 1;
	}
</style>